﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DataAccessLayer;

public partial class web_Controls_ctrl_vl_left_ntv_details : System.Web.UI.UserControl
{
    Common _common = null;
    public string mess = "";
    public string idGui = "", idNhan = "", type = "0",idLuu="";
    public Boolean chophepgui = false;
    protected void Page_Load(object sender, EventArgs e)
    {
        _common = new Common();
        if (Request.Params["id"] != null)
        {
            LoadNtvDetail(Request.Params["id"].ToString(),"");
            if (Session["NTDid"] == null || !(Boolean.Parse(Session["NTD_Active"].ToString()))) chophepgui = false;
            else { chophepgui = true; idGui = Session["NTDid"].ToString(); }
        }
		else if ((Request.Params["idntv"]!=null))
		{
			LoadNtvDetail("",Request.Params["idntv"].ToString());
            if (Session["NTDid"] == null || !(Boolean.Parse(Session["NTD_Active"].ToString()))) chophepgui = false;
            else { chophepgui = true; idGui = Session["NTDid"].ToString(); }
		}
    }
    void LoadNtvDetail(string id,string idntv)
    {
		if (!string.IsNullOrEmpty(id))
		{
			string _sql = "select * from NguoiTimViec_ho_so where ma_ho_so = '" + id + "'";
			DataSet _ds = _common.ExeceuteDataset(_sql);
			if (_ds.Tables[0].Rows.Count > 0)
			{
				if (LoadNguoitimviec(_ds.Tables[0].Rows[0]["ma_nguoi"].ToString()))
				{
					idNhan = _ds.Tables[0].Rows[0]["ma_nguoi"].ToString();
					idLuu = _ds.Tables[0].Rows[0]["ma_nguoi"].ToString() + "_" + _ds.Tables[0].Rows[0]["ma_ho_so"].ToString(); ;

					LoadChucvu(_ds.Tables[0].Rows[0]["ma_ho_so"].ToString());
					LoadGiolam(_ds.Tables[0].Rows[0]["ma_ho_so"].ToString());
					LoadHinhthuCty(_ds.Tables[0].Rows[0]["ma_ho_so"].ToString());
					LoadChucdanh(_ds.Tables[0].Rows[0]["ma_ho_so"].ToString());
					LoadHocvan(_ds.Tables[0].Rows[0]["ma_nguoi"].ToString());
					LoadNghiepvu(_ds.Tables[0].Rows[0]["ma_nguoi"].ToString());
					LoadNoilamviec(_ds.Tables[0].Rows[0]["ma_ho_so"].ToString());
					LoadKynangmem(_ds.Tables[0].Rows[0]["ma_nguoi"].ToString());
					LoadViecdalam(_ds.Tables[0].Rows[0]["ma_nguoi"].ToString());
				}
				else
				{
					Response.Redirect("Default.aspx");
				}
			}
		}else if (!string.IsNullOrEmpty(idntv)){
            string _sql = "select * from NguoiTimViec_ho_so where kich_hoat=1 and ma_nguoi = '" +idntv + "'";
            DataSet _ds = _common.ExeceuteDataset(_sql);
            if (_ds.Tables[0].Rows.Count > 0)
            {
                if (LoadNguoitimviec(_ds.Tables[0].Rows[0]["ma_nguoi"].ToString()))
                {
                    idNhan = _ds.Tables[0].Rows[0]["ma_nguoi"].ToString();
                    idLuu = _ds.Tables[0].Rows[0]["ma_nguoi"].ToString() + "_" + _ds.Tables[0].Rows[0]["ma_ho_so"].ToString(); ;

                    LoadChucvu(_ds.Tables[0].Rows[0]["ma_ho_so"].ToString());
                    LoadGiolam(_ds.Tables[0].Rows[0]["ma_ho_so"].ToString());
                    LoadHinhthuCty(_ds.Tables[0].Rows[0]["ma_ho_so"].ToString());
                    LoadChucdanh(_ds.Tables[0].Rows[0]["ma_ho_so"].ToString());
                    LoadHocvan(_ds.Tables[0].Rows[0]["ma_nguoi"].ToString());
                    LoadNghiepvu(_ds.Tables[0].Rows[0]["ma_nguoi"].ToString());
                    LoadNoilamviec(_ds.Tables[0].Rows[0]["ma_ho_so"].ToString());
                    LoadKynangmem(_ds.Tables[0].Rows[0]["ma_nguoi"].ToString());
                    LoadViecdalam(_ds.Tables[0].Rows[0]["ma_nguoi"].ToString());
                }
                else
                {
                    Response.Redirect("Default.aspx");
                }
            }
        }
    }
    bool LoadNguoitimviec(string ma_ntv)
    {
        DataSet _ds_ntv = _common.ExeceuteDataset("select * from ConNguoi_nguoi where ma_nguoi = '" + ma_ntv + "'");
        if (_ds_ntv.Tables[0].Rows.Count > 0)
        {
            if ((bool)_ds_ntv.Tables[0].Rows[0]["kich_hoat"])
            {
                lbl_ma_uv.Text = _ds_ntv.Tables[0].Rows[0]["ma_nguoi"].ToString();
                lbl_cannang.Text = _ds_ntv.Tables[0].Rows[0]["can_nang"].ToString() + " (kg)";
                lbl_chieucao.Text = _ds_ntv.Tables[0].Rows[0]["chieu_cao"].ToString() + " (cm)";
				
				if (Session["NTV_id"] == null && Session["NTDuser"] == null && Session["UserID"] == null)
                {
                    lbl_diachi.Text = "Bạn không có đủ quyền xem mục này";
                    lbl_dienthoai.Text = "Bạn không có đủ quyền xem mục này";
                    lbl_email.Text = "Bạn không có đủ quyền xem mục này";
                    
                }
                else
                {
                    lbl_diachi.Text = (bool)_ds_ntv.Tables[0].Rows[0]["ht_diachi"] == true ? _ds_ntv.Tables[0].Rows[0]["dia_chi_chi_tiet"].ToString() + " " + _common.execScalar("select dbo.fcGetDiaChiChiTiet ('" + _ds_ntv.Tables[0].Rows[0]["dia_chi"].ToString() + "')") : "Liên hệ với trung tâm";
					lbl_dienthoai.Text = (bool)_ds_ntv.Tables[0].Rows[0]["ht_dienthoai"] == true ? _ds_ntv.Tables[0].Rows[0]["dien_thoai_di_dong"].ToString() : "Liên hệ với trung tâm";
					lbl_email.Text = (bool)_ds_ntv.Tables[0].Rows[0]["ht_email"] == true ? _ds_ntv.Tables[0].Rows[0]["email"].ToString() : "Liên hệ với trung tâm";
                }
                
				
				
                lbl_goitinh.Text = (bool)_ds_ntv.Tables[0].Rows[0]["gioi_tinh"] == true ? "Nam" : "Nữ";
                lbl_honnhan.Text = (bool)_ds_ntv.Tables[0].Rows[0]["hon_nhan"] == true ? "Đã có gia đình" : "Chưa có gia đình";
                lbl_ngaysinh.Text = Convert.ToDateTime(_ds_ntv.Tables[0].Rows[0]["ngay_sinh"].ToString()).ToString("dd/MM/yyyy");
                lbl_ten_uv.Text = _ds_ntv.Tables[0].Rows[0]["ho_ten"].ToString();

            }
            else return false;
        }
        return true;
    }
    void LoadViecdalam(string ma)
    {
        DataSet _ds_ = _common.ExeceuteDataset("select * from NguoiTimViec_kinh_nghiem_lam_viec as A inner join DanhMuc_chuc_danh as B on A.ma_chuc_danh = B.ma_chuc_danh where A.ma_nguoi ='" + ma + "'");
        if (_ds_.Tables[0].Rows.Count > 0)
        {
            lbl_viec_dalam.Text += "Tên công ty : " + _ds_.Tables[0].Rows[0]["ten_cong_ty"].ToString() + " <br />";
            lbl_viec_dalam.Text += "Chức danh : " + _ds_.Tables[0].Rows[0]["ten_chuc_danh"].ToString() + " <br />";
            lbl_viec_dalam.Text += "Kinh nghiệm : " +_ds_.Tables[0].Rows[0]["kinh_nghiem"].ToString() + " <br />";
            lbl_viec_dalam.Text += "Mức lương : " + _ds_.Tables[0].Rows[0]["muc_luong"].ToString();
        }
    }
    void LoadKynangmem(string ma)
    {
        DataSet _ds_ = _common.ExeceuteDataset("select * from ConNguoi_kha_nang_mem as A inner join DanhMuc_kha_nang_mem as B on A.ma_kn_mem = B.ma_kn_mem where A.ma_nguoi ='" + ma + "'");
        if (_ds_.Tables[0].Rows.Count > 0)
        {
            for (int i = 0; i < _ds_.Tables[0].Rows.Count; i++)
            {
                lbl_kynang_mem.Text += _ds_.Tables[0].Rows[i]["ten_kn_mem"].ToString() + " <br />";
            }
        }
    }
    void LoadNoilamviec(string ma)
    {
        DataSet _ds_ = _common.ExeceuteDataset("select * from NguoiTimViec_thanh_pho_lam_viec as A inner join DanhMuc_dia_chi as B on A.ma_dia_chi = B.ma_dia_chi where A.ma_ho_so ='" + ma + "'" );
        if (_ds_.Tables[0].Rows.Count > 0)
        {
            for (int i = 0; i < _ds_.Tables[0].Rows.Count; i++)
            {
                lbl_nguyenvong_noilamviec.Text += _ds_.Tables[0].Rows[i]["ten_dia_chi"].ToString() + " <br />";
            }
        }
    }
    void LoadNghiepvu(string ma)
    {
        DataSet _ds_ = _common.ExeceuteDataset("select * from ConNguoi_nghiep_vu as A inner join DanhMuc_nghiep_vu as B on A.ma_nghiep_vu = B.ma_nghiep_vu where A.ma_nguoi ='" + ma + "'");
        if (_ds_.Tables[0].Rows.Count > 0)
        {
            for (int i = 0; i < _ds_.Tables[0].Rows.Count; i++)
            {
                if ((bool)_ds_.Tables[0].Rows[i]["ngoai_ngu"])
                {
                    lbl_chuyenmon_ngoaingu.Text = _ds_.Tables[0].Rows[i]["ten_nghiep_vu"].ToString() + " (kinh nghiệm " + _ds_.Tables[0].Rows[i]["kinh_nghiem"].ToString() + " tháng)";
                }
                if ((bool)_ds_.Tables[0].Rows[i]["tin_hoc"])
                {
                    lbl_chuyenmon_tinhoc.Text = _ds_.Tables[0].Rows[i]["ten_nghiep_vu"].ToString() + " (kinh nghiệm " + _ds_.Tables[0].Rows[i]["kinh_nghiem"].ToString() + " tháng)";
                }
            }
        }
    }
    void LoadHocvan(string ma)
    {
        DataSet _ds_ = _common.ExeceuteDataset("select * from ConNguoi_hoc_van_chuyen_mon as A inner join DanhMuc_hoc_van as B on A.ma_hoc_van = B.ma_hoc_van inner join DanhMuc_chuyen_mon as C on A.ma_chuyen_mon = C.ma_chuyen_mon where A.ma_nguoi ='" + ma + "'");
        if (_ds_.Tables[0].Rows.Count > 0)
        {
            lbl_chuyenmon_hocvan.Text = _ds_.Tables[0].Rows[0]["ten_hoc_van"].ToString();
            lbl_chuyenmon_nganhnghe.Text = _ds_.Tables[0].Rows[0]["ten_chuyen_mon"].ToString();
        }
    }
    void LoadChucdanh(string ma)
    {
        DataSet _ds_ = _common.ExeceuteDataset("select * from NguoiTimViec_ho_so as A inner join DanhMuc_chuc_danh as B on A.chuc_danh_mong_muon"+
            " = B.ma_chuc_danh where ma_ho_so = '" + ma + "'");
        if (_ds_.Tables[0].Rows.Count > 0)
        {
            lbl_nguyenvong_chucdanh.Text = _ds_.Tables[0].Rows[0]["ten_chuc_danh"].ToString();
			if(_ds_.Tables[0].Rows[0]["muc_luong_mong_muon"].ToString()=="0")
				lbl_nguyenvong_mucluong.Text="Lương thỏa thuận";
			else
				lbl_nguyenvong_mucluong.Text = _ds_.Tables[0].Rows[0]["muc_luong_mong_muon"].ToString() + " (đồng)";
        }
    }
    void LoadHinhthuCty(string ma)
    {
        DataSet _ds_ = _common.ExeceuteDataset("select * from NguoiTimViec_qui_mo_cong_ty as A inner join DanhMuc_so_huu as B on A.ma_so_huu = B.ma_so_huu where A.ma_ho_so ='" + ma + "'");
        if (_ds_.Tables[0].Rows.Count > 0)
            lbl_nguyenvong_hinhthuc_cty.Text = _ds_.Tables[0].Rows[0]["ten_so_huu"].ToString();
    }
    void LoadChucvu(string ma)
    {
        DataSet _ds_ = _common.ExeceuteDataset("select * from NguoiTimViec_mong_muon_chuyen_mon as A inner join DanhMuc_chuyen_mon as B on A.ma_chuyen_mon = B.ma_chuyen_mon where A.ma_ho_so ='" + ma + "'");
        if (_ds_.Tables[0].Rows.Count > 0)
            lbl_nguyenvong_chucvu.Text = _ds_.Tables[0].Rows[0]["ten_chuyen_mon"].ToString();
    }
    void LoadGiolam(string ma)
    {
        DataSet _ds_ = _common.ExeceuteDataset("select * from NguoiTimViec_thoi_gian_lam_viec as A inner join DanhMuc_thoi_gian_lam_viec as B on A.ma_thoi_gian_lv = B.ma_thoi_gian_lv where A.ma_ho_so ='" + ma + "'");
        if (_ds_.Tables[0].Rows.Count > 0)
            lbl_nguyenvong_giolam.Text = _ds_.Tables[0].Rows[0]["ten_thoi_gian_lv"].ToString();
    }
}